package cn.tedu.fresheveryday.mapper;

import cn.tedu.fresheveryday.pojo.entity.OrderStatusHistory;
import cn.tedu.fresheveryday.pojo.vo.OrderStatusHistoryVO;
import cn.tedu.fresheveryday.pojo.vo.OrderStatusSimpleVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderStatusHistoryMapper {
    /**
     * 添加订单状态
     * @param status
     */
    @Insert(
            "insert into order_status_history (" +
                "state, order_id, update_time" +
            ") values (" +
                "#{state}, #{orderId}, #{updateTime}" +
            ")"
    )
    void insert(OrderStatusHistory status);

    /**
     * 通过订单id查询订单状态历史
     * @param orderId 订单id
     * @return
     */
    @Select(
            "select state, order_id, update_time from order_status_history " +
            "where order_id = #{orderId}"
    )
    @Result(column = "order_id", property = "orderId")
    @Result(
            column = "state", property = "status", javaType = OrderStatusSimpleVO.class,
            one = @One(select = "cn.tedu.fresheveryday.mapper.OrderStatusMapper.selectById")
    )
    @Result(column = "update_time", property = "updateTime")
    List<OrderStatusHistoryVO> selectByOrderId(String orderId);

    /**
     * 通过订单号删除订单状态历史
     * @param orderId
     */
    @Delete("delete from order_status_history where order_id = #{orderId}")
    void deleteByOrderId(String orderId);
}